<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DbConnection
 *
 * @author Nhân
 */
class DbConnection {
    private static $url = "localhost";
    private static $userName = "root";
    private static $password = "";
    private static $inst = null;
    
    private $conn = null;
    
    private function __construct() { }

    public static function getInstance() {
        if (self::$inst == null) {
            self::$inst = new self();
        }
        return self::$inst;
    }
    
    public function openConnection() {
        if ($this->conn == null) {
            $this->conn = mysql_connect(self::$url, self::$userName, self::$password) or die ('Cannot connect to database');
            mysql_select_db("CookieDb") or die("Cannot select database CookieDb");
            mysql_query("SET NAMES `utf8`", $this->conn);
        }
        return $this->conn;
    }
    
    public function closeConnection() {
        if ($this->conn != null) {        
            //mysql_close($this->conn);
        }
    }
}

?>
